//
//  UIBarButtonItem.swift
//  weibo10
//
//  Created by apple on 16/5/16.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

//在扩展中只能添加便利构造函数
        convenience init(imageName: String,target: AnyObject?, action: Selector)
        {
        //创建按钮
            let button = UIButton()
            button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
            
            button.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
            
            button.sizeToFit()
            
            //设置点击事件
            button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
            self.init(customView:button)
        
        }



////创建带按钮的UIBarButtonItem，class表示类方法
//class func createBarButtonItem(imageName:String) -> UIBarButtonItem
//{
//let button = UIButton()
//    button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
//    
//    button.setImage(UIImage(named: imageName + "_highlighte"), forState: UIControlState.Highlighted)
//    
//    //让控件根据里面的内容设置大小
//    button.sizeToFit()
//    
//    //将按钮添加到customView上
//    return UIBarButtonItem(customView: button)
//}
}